classdef NIntegrate < handle
    %NIntegrate Numerical integration
    %   Perfoms integration using mid-point method
    %
    % Properties:
    %         f       %function handle
    %         h_req   %requested step size
    %         h       %actual step size
    %         a       %start of integral
    %         b       %end of integral
    %         EndPoints %End points of sub-steps
    %         Int_Result %Result
    
    properties
        f       %function handle
        h_req   %requested step size
        h       %actual step size
        a       %start of integral
        b       %end of integral
        EndPoints %End points of sub-steps
        Int_Result %Result
        
    end
    
    methods
        function find_h(obj)
            %This code is simply taken from our script
            %Note that a->obj.a, etc for working with class properties
            
            Nsteps=ceil((obj.b-obj.a)/obj.h_req)+1;
            obj.EndPoints=linspace(obj.a,obj.b,Nsteps);
            %calculate spacing
            obj.h=obj.EndPoints(2)-obj.EndPoints(1);
        end
        
        function IntFunction(obj)
            %This code is simply taken from our script
            %Note that Int_Result->obj.Int_Result, etc for working with class properties
            
            obj.Int_Result=0;
            for ii=1:length(obj.EndPoints)-1
                x_mid=obj.EndPoints(ii)+obj.h/2;
                obj.Int_Result=obj.Int_Result+obj.f(x_mid)*obj.h;
            end
        end
        
        
    end
    
end

